package com.orientsec.autotest.project.system.autoKeywordType.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.autoKeywordType.domain.AutoKeywordType;
import com.orientsec.autotest.project.system.autoKeywordType.service.IAutoKeywordTypeService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * 关键字种类信息操作处理
 * 
 * @author autotest
 * @date 2020-01-09
 */
@Controller
@RequestMapping("/system/autoKeywordType")
public class AutoKeywordTypeController extends BaseController
{
    private String prefix = "system/autoKeywordType";
	
	@Autowired
	private IAutoKeywordTypeService autoKeywordTypeService;
	
	@RequiresPermissions("system:autoKeywordType:view")
	@GetMapping()
	public String autoKeywordType()
	{
	    return prefix + "/autoKeywordType";
	}
	
	/**
	 * 查询关键字种类列表
	 */
	@RequiresPermissions("system:autoKeywordType:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AutoKeywordType autoKeywordType)
	{
		startPage();
        List<AutoKeywordType> list = autoKeywordTypeService.selectAutoKeywordTypeList(autoKeywordType);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出关键字种类列表
	 */
	@RequiresPermissions("system:autoKeywordType:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AutoKeywordType autoKeywordType)
    {
    	List<AutoKeywordType> list = autoKeywordTypeService.selectAutoKeywordTypeList(autoKeywordType);
        ExcelUtil<AutoKeywordType> util = new ExcelUtil<AutoKeywordType>(AutoKeywordType.class);
        return util.exportExcel(list, "autoKeywordType");
    }
	
	/**
	 * 新增关键字种类
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存关键字种类
	 */
	@RequiresPermissions("system:autoKeywordType:add")
	@Log(title = "关键字种类", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AutoKeywordType autoKeywordType)
	{		
		return toAjax(autoKeywordTypeService.insertAutoKeywordType(autoKeywordType));
	}

	/**
	 * 修改关键字种类
	 */
	@GetMapping("/edit/{keywordId}")
	public String edit(@PathVariable("keywordId") Integer keywordId, ModelMap mmap)
	{
		AutoKeywordType autoKeywordType = autoKeywordTypeService.selectAutoKeywordTypeById(keywordId);
		mmap.put("autoKeywordType", autoKeywordType);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存关键字种类
	 */
	@RequiresPermissions("system:autoKeywordType:edit")
	@Log(title = "关键字种类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AutoKeywordType autoKeywordType)
	{		
		return toAjax(autoKeywordTypeService.updateAutoKeywordType(autoKeywordType));
	}
	
	/**
	 * 删除关键字种类
	 */
	@RequiresPermissions("system:autoKeywordType:remove")
	@Log(title = "关键字种类", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(autoKeywordTypeService.deleteAutoKeywordTypeByIds(ids));
	}
	
}
